package com.sentinel.demo01;

import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SentinelDemo01Main {
    public static void main(String[] args) {
        SpringApplication.run(SentinelDemo01Main.class,args);
        // 设置一个FlowRule流量控制规则，绑定sayHi方法，限制QPS值为1(测试)
        List<FlowRule> flowRules = new ArrayList<>();
        // 定义sayHi的规则
        FlowRule qpsRule = new FlowRule();
        // 1.绑定资源
        qpsRule.setResource("sayHi");
        // 2.设置限流类型，0表示并发限流，1表示qps限流
        qpsRule.setGrade(1);
        // 3.设置qps阈值
        qpsRule.setCount(1);
        // 4.添加到规则列表中
        flowRules.add(qpsRule);
        // 5.加载规则，给sentinel使用
        FlowRuleManager.loadRules(flowRules);
    }
}